package com.jerry.walking.module.activityPage.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jerry.walking.R;
import com.jerry.walking.base.BaseViewHolder;
import com.jerry.walking.base.MyBaseAdapter;
import com.jerry.walking.module.activityPage.activity.CategorySearchActivity;
import com.jerry.walking.module.activityPage.bean.Category;
import com.squareup.picasso.Picasso;

import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2016/5/10 0010.
 */
public class CategoryAdapter extends MyBaseAdapter<Category.CatsBean>{
    private Context context;

    public CategoryAdapter(Context context, List<Category.CatsBean> list){
        super(context, list);
        this.context = context;
    }

    @Override
    public int getLayoutId(){
        return R.layout.item_category;
    }

    @Override
    public BaseViewHolder getViewHolder(){
        return new ViewHolder();
    }

    @Override
    public void bindViews(View view, BaseViewHolder viewHolder){
        ViewHolder holder = (ViewHolder) viewHolder;
        final Category.CatsBean item = getItem(holder.position);
        holder.tv_category.setText(item.getName());
        Picasso.with(context).load(item.getIcon()).into(holder.iv_category);
        view.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                Intent intent = new Intent(context, CategorySearchActivity.class);
                intent.putExtra("keyword",item.getName());
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
            }
        });
    }

    public class ViewHolder extends BaseViewHolder
    {
        @BindView(R.id.iv_category)
        ImageView iv_category;

        @BindView(R.id.tv_category)
        TextView tv_category;
    }

}
